package net.flyinggroup.reactor.handson;

import net.flyinggroup.reactor.handson.fn.ReactiveFunction;
import org.springframework.http.server.reactive.HttpHandler;
import org.springframework.http.server.reactive.ReactorHttpHandlerAdapter;
import org.springframework.web.reactive.function.server.RouterFunction;
import org.springframework.web.reactive.function.server.RouterFunctions;
import org.springframework.web.reactive.function.server.ServerResponse;
import reactor.netty.DisposableServer;
import reactor.netty.http.server.HttpServer;

public class ReactorFnApplication {
    public static void main(String[] args) {
        RouterFunction<ServerResponse> helloRoute = new ReactiveFunction().getFunction();
        HttpHandler httpHandler = RouterFunctions.toHttpHandler(helloRoute);
        ReactorHttpHandlerAdapter adapter = new ReactorHttpHandlerAdapter(httpHandler);
        DisposableServer server = HttpServer.create()
                .host("127.0.0.1")
                .port(6868)
                .handle(adapter)
                .bind()
                .block();
        assert server != null;
        server.onDispose().block();
    }
}
